package com.inspireink.project.controller;

import com.inspireink.project.entity.InspireUser;
import com.inspireink.project.service.InspireUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/auth")
public class InspireUserController {
    @Autowired
    private InspireUserService inspireUserService;

    @PostMapping("/register")
    public String register(@RequestBody InspireUser user) {
        inspireUserService.register(user);
        return "User registered successfully";
    }

    @PostMapping("/login")
    public String login(@RequestBody InspireUser user) {
        InspireUser loggedInUser = inspireUserService.login(user.getUsername(), user.getPassword());
        if (loggedInUser != null) {
            return "Login successful";
        } else {
            return "Invalid username or password";
        }
    }
}
